package club.sh.generator.utils;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.util.Scanner;

/**
 * @author 林思浩
 * @date 2020/07/24 10:17
 */
public class ScannerUtil {


    /**
     * 读取控制台内容stirng
     * @param tip
     * @return
     */
    public static String scanner(String tip) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder help = new StringBuilder();
        help.append("请填写" + tip + "?");
        System.out.println(help.toString());
        if (scanner.hasNext()) {
            String ipt = scanner.next();
            if (StringUtils.isNotBlank(ipt)) {
                return ipt;
            }
        }
        return null;
    }

    /**
     * 读取控制台转boolean
     * @param tip
     * @return
     */
    public static boolean bScanner(String tip) {
        Scanner scanner = new Scanner(System.in);
        for(;;) {
            StringBuilder help = new StringBuilder();
            help.append(tip + "？(T or F)");
            System.out.println(help.toString());
            if (scanner.hasNext()) {
                String ipt = scanner.next();
                if("T".equalsIgnoreCase(ipt)) {
                    return true;
                } else if("F".equalsIgnoreCase(ipt)) {
                    return false;
                } else {
                    System.err.println("只能输入“T”或“F”~");
                }
            }
        }
    }

}
